//
//  BuyNowBottom.m
//  夺宝吧
//
//  Created by xiaocai on 15/7/3.
//  Copyright (c) 2015年 FangYuan. All rights reserved.
//

#import "BuyNowBottom.h"
#import "ShoppingCarVC.h"

@interface BuyNowBottom ()
{
    __weak IBOutlet UIButton *buyNowBtn;
    __weak IBOutlet UIButton *addToCarBtn;
}
@end
@implementation BuyNowBottom
- (void)awakeFromNib
{
    buyNowBtn.layer.masksToBounds = YES;
    buyNowBtn.layer.cornerRadius = 2;
    buyNowBtn.backgroundColor = QBB_RED_COLOR;
    addToCarBtn.layer.masksToBounds = YES;
    addToCarBtn.titleLabel.textColor = QBB_RED_COLOR;
    addToCarBtn.layer.cornerRadius = 2;
    addToCarBtn.layer.borderColor = QBB_RED_COLOR.CGColor;
    addToCarBtn.layer.borderWidth = 1.0;
}

//立即抢购
- (IBAction)buyBtnOnClick:(id)sender {
    
    if(self.car_model != nil){
        
        if ([[WYDataBase sharedDataBase]insertPdcToCarWithModel:self.car_model]) {
            [self.father updateTongZhi];
            
            ShoppingCarVC *shopVC = [ShoppingCarVC shareShoppingCarVC];
            shopVC.firstFlag = YES;
            
            [[WYMainTabBarVC shareMainTaBarVC] changeSelectedWithIndex:2];
            [[WYMainTabBarVC shareMainTaBarVC]updateCountToCar];
            [[WYMainTabBarVC shareMainTaBarVC].navigationController popToRootViewControllerAnimated:YES];
        }
        else{
            if([[WYDataBase sharedDataBase] isExistInCarWithModel:self.car_model]){
                [[WYMainTabBarVC shareMainTaBarVC] changeSelectedWithIndex:2];
                [[WYMainTabBarVC shareMainTaBarVC]updateCountToCar];
                [[WYMainTabBarVC shareMainTaBarVC].navigationController popToRootViewControllerAnimated:YES];//            [WYPublic showMessageWithTitle:@"" Msg:@"已经添加在购物车中!"];
            }
        }
        
    }

}

- (IBAction)addBtnOnClick:(id)sender {
    
    //加入购物车
    if(self.car_model != nil){
        
        
        if ([[WYDataBase sharedDataBase]insertPdcToCarWithModel:self.car_model]) {
            ShoppingCarVC *shopVC = [ShoppingCarVC shareShoppingCarVC];
            shopVC.firstFlag = YES;
            
            [WYPublic showMessageWithTitle:@"" Msg:@"加入购物车成功!"];
            [self.father updateTongZhi];
            [[WYMainTabBarVC shareMainTaBarVC]updateCountToCar];
        }
        else{
            if([[WYDataBase sharedDataBase] isExistInCarWithModel:self.car_model]){
                [WYPublic showMessageWithTitle:@"" Msg:@"已经添加在购物车中!"];
            }
        }
        
    }
    
}

@end
